package com.ztgf.search.api.client;

import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.search.models.service.SynchronizationService;
import com.ztgf.search.models.vo.SynchronizationVo;
import com.ztgf.shopping.models.dto.shop.ShopAnnualFeeDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：Eric
 * @description：同步商品和店铺
 * @date ：2021/8/16 11:03
 */
@RestController
@RequestMapping("/api/synchronization")
@Api(value = "SynchronizationController", tags = "同步商品和店铺")
public class SynchronizationController {
    @DubboReference
    private SynchronizationService synchronizationService;
    @ApiOperation(value = "获取店铺和商品数量",notes = "获取店铺和商品数量")
    @PostMapping(value = "/getByShopAndGoods")
    public Result getByShopAndGoods() {
        SynchronizationVo synchronizationVo=synchronizationService.selectESAndShop();
        if (synchronizationVo!=null){
            return new Result<>(synchronizationVo);
        }
        return new Result();
    }


    @ApiOperation(value = "同步店铺和商品",notes = "同步店铺和商品")
    @PostMapping(value = "/updateEsShopAndGoods")
    public Result updateEsShopAndGoods() {
        boolean a=synchronizationService.updateEsShopAndGoods();
        if (a){
            return new Result<>();
        }
         return new Result<>(CodeEnum.FAIL_100007);
    }


    @ApiOperation(value = "删除索引",notes = "删除索引")
    @PostMapping(value = "/deleteEsIndex")
    public Result deleteEsIndex(String index) {
        boolean a=synchronizationService.deleteEsIndex(index);
        if (a){
            return new Result<>();
        }
        return new Result<>(CodeEnum.FAIL_100007);
    }
}
